package com.orangelife.mobile.individual.biz;

import com.common.sp.UserSp;
import com.curry.android.http.OrangeDataHandler;
import com.curry.android.http.OrangeErrorHandler;
import com.curry.android.http.VolleyHttpUtil;
import com.orangelife.mobile.constants.Constant;

import org.json.JSONObject;

import java.util.Map;


/**
 * 个人中心
 * <p/>
 * Created by wgf on 2016/7/22.
 */
public class PersonalBiz {

    public static void getPersonalInfo(VolleyHttpUtil.ResponseCallBack callback) {
        VolleyHttpUtil.getInstance().getWithCallbackWithTag(Constant.PERSONAL_STATE, callback, "PersonalBiz_PAGE4");
    }

    public static int handlePersonalInfo(JSONObject response) {
        if (OrangeErrorHandler.getInstance().isSuccess(response,false)) {
            Map<String, Object> map = OrangeDataHandler.getMapWithEntityNoGson(response);
            if (map != null) {
                UserSp.setHasCert(String.valueOf(map.get("certificationStat")));
                int msgCount = 0;
                try {
                    msgCount = Integer.parseInt(String.valueOf(map.get("messageCount")));
                } catch (NumberFormatException e) {
                    e.printStackTrace();
                }
                return msgCount;

            }
        }
        return 0;
    }

    public static void getOtherService(VolleyHttpUtil.ResponseCallBack callback) {
        VolleyHttpUtil.getInstance().getWithCallbackWithTag(Constant.OTHER_SERVICE, callback, "PersonalBiz_PAGE4");
    }

    /** 取消所有PAGE4的网络请求 */
    public static void cancelPage4Request() {
        VolleyHttpUtil.getInstance().cancel("PersonalBiz_PAGE4");
    }
}
